﻿using MT.Common;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;
using System;
using System.Collections.Generic;
using System.IO;
namespace MT.WebApi.Core.ConfigureServices
{
    public static class SwaggerConfiguration
    {
        public static void SwaggerServer(this IServiceCollection services)
        {
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Title = "MedicalBeauty RESTful Api",
                    Version = "v1",
                    Description = $"{MvcContext.GetContext().Request.Scheme}://{MvcContext.GetContext().Request.Host}/profiler/results-index",
                    License = new License
                    {
                        Name = "双美医疗-原型",
                        Url = "http://xinao.bubaocloud.com:9393/%E6%99%BA%E6%85%A7%E5%8C%BB%E7%BE%8E/",
                    },
                    Contact = new Contact { Name = "双美医疗-文档", Url = "https://www.yuque.com/shr9gp/mbeauty/about" },
                });

                var xmlPath = Path.Combine(AppContext.BaseDirectory, "MT.Rest.xml");
                //  var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                // var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath, true);

                // var IssuerName = (ConfigHelper.GetSection("Audience", "Issuer"));
                var restCorePath = Path.Combine(AppContext.BaseDirectory, "MT.Rest.Core.xml");
                c.IncludeXmlComments(restCorePath, true);
                var security = new Dictionary<string, IEnumerable<string>> { { "Bearer", new string[] { } }, };
                c.AddSecurityRequirement(security);
                c.AddSecurityDefinition("Bearer", new ApiKeyScheme
                {
                    Description = "授权(数据将在请求头中进行传输) 参数结构: \"Authorization: Bearer {token}\"",
                    Name = "Authorization",
                    In = "header",
                    Type = "apiKey"
                });

            });
        }
    }
}
